/**
 * 项目名称:
 *
 * @Author: 夏国倩
 * @Date: 2023/10/13 15:43
 * @Copyright
 */
package wait;

public class Output implements Runnable{
    private Resource r;

    public Output(Resource r) {
        this.r = r;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (r) {
                //判断标记，是false，等待
                if (!r.flag){
                    try {
                        wait();
                    } catch (Exception e) {
                    }
                }
                System.out.println(r.name + "----->" + r.sex);
                //标记改为false，唤醒对方线程
                r.flag=false;
                r.notify();
            }
        }
    }
}
